package com.ly.service.impl;

import com.ly.mapper.EasybuyUserMapper;
import com.ly.mapper.UserVipMapper;
import com.ly.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.List;
import java.util.Map;

/**
 * @author 李岩
 * @date 2021/12/24-20:45
 * @describe
 */
@Configuration
@EnableScheduling
public class TaskServiceImpl {

    @Autowired
    private EasybuyUserMapper userMapper;
    @Autowired
    private UserVipMapper userVipMapper;

    //每个月1号的0点0分10秒启动
    //@Scheduled(cron = "10 0 0 1 * ?")
    @Scheduled(cron = "50 50 20 1 * ?")
    public void addUserVip(){
        List<Map<String, Object>> vipUserList = userVipMapper.findMonthVipUsers();
        for (Map<String, Object> map : vipUserList) {
            //System.out.println(11111);
            //System.out.println(map.get("userId")+";  total_cost=  "+map.get("total_cost"));
            userVipMapper.addVipUser(Integer.valueOf(map.get("userId").toString()), DateUtil.getNowDateYm());
        }
    }
}
